import os
import tkinter as tk
from tkinter import messagebox

def print_prescription():
    # 收集所有输入框的内容
    content = f"姓名：{name_entry.get()}\n"
    gender = "男" if male_var.get() == 1 else "女"
    content += f"性别：{gender}{'√' if male_var.get() == 1 else ''}{'√' if female_var.get() == 1 else ''}\n"
    content += f"年龄：{age_entry.get()}岁\n"
    content += f"联系电话：{address_phone_entry.get()}\n"
    insurance = "医保" if male_var.get() == 1 else "非医保"
    content += f"费别：{insurance}{'√' if male_var.get() == 1 else ''}\n"
    content += f"医保/就诊卡号：{medical_record_entry.get()}\n"
    content += f"门诊/住院病历号：{department_entry.get()}\n"
    content += f"临床诊断：{diagnosis_entry.get()}\n"
    content += f"皮试结果：{allergy_entry.get()}\n"
    content += f"开具日期：{year_entry.get()}年{month_entry.get()}月{day_entry.get()}日\n"
    content += "RP" + prescription_text_entry.get("1.0", "end-1c") + "\n"
    content += f"审核：{review_entry.get()}\n"
    content += f"调配：{dispensing_entry.get()}\n"
    content += f"医师：{physician_entry.get()}\n"
    content += f"核对、发药：{other_cost_entry.get()}\n"
    content += f"药品金额（元）：{total_entry.get()}\n"

# 主窗口
root = tk.Tk()
root.title("处方")
root.geometry("491x718")
root.resizable(False, False)
root.configure(bg='white')  # 设置主窗口背景色为白色

# 辅助变量定义
label_width = 50  # 标签宽度预估
entry_width = 40  # 输入框宽度预估

# 病人信息
x_base = 18  # 基础水平偏移量
y_base = 35  # 基础垂直偏移量
# 创建一个打印按钮
def on_print():
    print_prescription()
print_button = tk.Button(root, text="打印处方", command=on_print, bg='white', fg='black')
print_button.place(x=420, y=78)  # 按钮的位置可以根据实际界面调整
print_button.pack()

# 性别选择变量
male_var = tk.IntVar()
female_var = tk.IntVar()
male_checkbox = tk.Checkbutton(root, text="男", variable=male_var, bg='white', fg='black')
male_checkbox.place(x=x_base + 236, y=y_base + 88)
female_checkbox = tk.Checkbutton(root, text="女", variable=female_var, bg='white', fg='black')
female_checkbox.place(x=x_base + 277, y=y_base + 88)

# 费别选择变量
male_var = tk.IntVar()
female_var = tk.IntVar()
male_checkbox = tk.Checkbutton(root, text="医保", variable=male_var, bg='white', fg='black')
male_checkbox.place(x=x_base + 62, y=y_base + 143)
female_checkbox = tk.Checkbutton(root, text="非医保", variable=female_var, bg='white', fg='black')
female_checkbox.place(x=x_base + 119, y=y_base + 143)

# 其他控件初始化
name_label = tk.Label(root, text="上海星氧医疗美容门诊部 处方笺", font=("Arial", 14, "bold"), bg='white', fg='black')
name_label.place(x=x_base + 77, y=y_base + 41)

name_label = tk.Label(root, text="姓名：", bg='white', fg='black')
name_label.place(x=x_base + 5, y=y_base + 88)
name_entry = tk.Entry(root)
name_entry.place(x=x_base + 40 , y=y_base + 87)

gender_label = tk.Label(root, text="性别：", bg='white', fg='black')
gender_label.place(x=x_base + 175, y=y_base + 88)

age_label = tk.Label(root, text="年龄：", bg='white', fg='black')
age_label.place(x=x_base + 332, y=y_base + 88)
age_entry = tk.Entry(root, width=8)
age_entry.place(x=x_base + 368 , y=y_base + 87)
age_label = tk.Label(root, text="岁", bg='white', fg='black')
age_label.place(x=x_base + 436, y=y_base + 88)

address_phone_label = tk.Label(root, text="联系电话：", bg='white', fg='black')
address_phone_label.place(x=x_base + 5, y=y_base + 118)
address_phone_entry = tk.Entry(root, width=35)
address_phone_entry.place(x=x_base + 15 + label_width, y=y_base + 117)

fee_label = tk.Label(root, text="费别：", bg='white', fg='black')
fee_label.place(x=x_base + 5, y=y_base + 143)

medical_record_label = tk.Label(root, text="医保/就诊卡号：", bg='white', fg='black')
medical_record_label.place(x=x_base + 184, y=y_base + 143)
medical_record_entry = tk.Entry(root)
medical_record_entry.place(x=x_base + 234 + label_width, y=y_base + 143)

department_label = tk.Label(root, text="门诊/住院病历号：", bg='white', fg='black')
department_label.place(x=x_base + 5, y=y_base + 171)
department_entry = tk.Entry(root)
department_entry.place(x=x_base + 55 + label_width, y=y_base + 170)

department_label = tk.Label(root, text="科别/病区-床位号：", bg='white', fg='black')
department_label.place(x=x_base + 257, y=y_base + 171)
department_entry = tk.Entry(root, width=12)
department_entry.place(x=x_base + 360 , y=y_base + 170)

diagnosis_label = tk.Label(root, text="临床诊断：", bg='white', fg='black')
diagnosis_label.place(x=x_base + 5, y=y_base + 198)
diagnosis_entry = tk.Entry(root, width=35)
diagnosis_entry.place(x=x_base + 15 + label_width, y=y_base + 197)

allergy_label = tk.Label(root, text="皮试结果：", bg='white', fg='black')
allergy_label.place(x=x_base + 5, y=y_base + 228)
allergy_entry = tk.Entry(root)
allergy_entry.place(x=x_base + 25 + label_width, y=y_base + 227)

date_label = tk.Label(root, text="开具日期：", bg='white', fg='black')
date_label.place(x=x_base + 254, y=y_base + 228)

year_entry = tk.Entry(root, width=4)
year_entry.place(x=x_base + 315, y=y_base + 227)
year_label = tk.Label(root, text="年", bg='white', fg='black')
year_label.place(x=x_base + 362, y=y_base + 228)

month_entry = tk.Entry(root, width=2)
month_entry.place(x=x_base + 378, y=y_base + 227)
month_label = tk.Label(root, text="月", bg='white', fg='black')
month_label.place(x=x_base + 398, y=y_base + 228)

day_entry = tk.Entry(root, width=2)
day_entry.place(x=x_base + 412, y=y_base + 227)
day_label = tk.Label(root, text="日", bg='white', fg='black')
day_label.place(x=x_base + 436, y=y_base + 228)

prescription_text_label = tk.Label(root, text="Rp", font=("Arial", 14, "bold"), bg='white', fg='black')
prescription_text_label.place(x=x_base + 16, y=y_base + 258)
prescription_text_entry = tk.Text(root, height=23, width=52)
prescription_text_entry.place(x=x_base + 42 , y=y_base + 292)

# 处方相关信息
review_label = tk.Label(root, text="审核：", bg='white', fg='black')
review_label.place(x=x_base + 5, y=y_base + 611)
review_entry = tk.Entry(root, width=10)
review_entry.place(x=x_base + 40 , y=y_base + 610)

dispensing_label = tk.Label(root, text="调配：", bg='white', fg='black')
dispensing_label.place(x=x_base + 133, y=y_base + 611)
dispensing_entry = tk.Entry(root, width=12)
dispensing_entry.place(x=x_base + 170 , y=y_base + 610)

physician_label = tk.Label(root, text="医师：", bg='white', fg='black')
physician_label.place(x=x_base + 275, y=y_base + 611)
physician_entry = tk.Entry(root, width=16)
physician_entry.place(x=x_base + 315 , y=y_base + 610)

other_cost_label = tk.Label(root, text="核对、发药：", bg='white', fg='black')
other_cost_label.place(x=x_base + 5, y=y_base + 643)
other_cost_entry = tk.Entry(root)
other_cost_entry.place(x=x_base + 25 + label_width, y=y_base + 642)

total_label = tk.Label(root, text="药品金额（元）：", bg='white', fg='black')
total_label.place(x=x_base + 275, y=y_base + 643)
total_entry = tk.Entry(root, width=12)
total_entry.place(x=x_base + 360 , y=y_base + 642)

# 运行主循环
root.mainloop()